#include "stdafx.h"

#include <QtGui/QApplication>
#include <QtCore/QPoint>
#include <QtCore/QFile>
#include <QtCore/QDebug>
#include <QtGui/QMainWindow>
#include <QtCore/QUrl>

#include <QtGui/QTextBlock>
#include <QtGui/QTextEdit>
#include <QtGui/QLineEdit>
#include <QtGui/QDateEdit>
#include <QtGui/QTimeEdit>
#include <QtGui/QFocusEvent>
#include <QtGui/QAbstractTextDocumentLayout>

#include <QtDeclarative/QDeclarativeEngine>
#include <QtDeclarative/QDeclarativeComponent>

#include "../../scriptEngine/vqmlcompiler.h"
#include "../../scriptEngine/vblankview.h"
#include "../../scriptEngine/vblank.h"

class SShelper: public QObject
{
	Q_OBJECT

public:
	SShelper(VBlank* blank, VBlankView* blankView, QObject* parent)
		: m_blank(blank)
		, m_blankView(blankView)
		, QObject(parent)
	{
	}

public slots:
	void blankChange()
	{
		m_blankView->update(m_blank);
	}

private:
	VBlank* m_blank;
	VBlankView* m_blankView;
};

int main(int argc, char *argv[])
{
	QApplication a(argc, argv);
	
	QString scriptName("testse.qml");
	QFile fScript(scriptName);
	if (!fScript.open(QIODevice::ReadOnly))
	{
		qDebug() << "open file error";
		return 0;
	}

	QMainWindow* mw = new QMainWindow;
	VBlankView* bv = new VBlankView(mw);
	mw->setCentralWidget(bv->widget());
	mw->show();

	VBlank* blank;
	{
		VQMLCompiler compiler;	
		blank = compiler.execute(fScript.readAll(), QUrl(scriptName));
		
	
	if (!blank)
	{
		qDebug() << compiler.errors();
		return 0;
	}
	
	}

	bv->update(blank);

	SShelper ssHelper(blank, bv, mw);
	QObject::connect(blank, SIGNAL(blankChanged()), &ssHelper, SLOT(blankChange()));
	
	return a.exec();
}

#include "main.moc"
